// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyModelFitAtts.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>

// ****************************************************************************
// Module: PyModelFitAtts
//
// Purpose:
//   This file contains attributes for the ModelFit operator.
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a ModelFitAtts.
//
struct ModelFitAttsObject
{
    PyObject_HEAD
    ModelFitAtts *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewModelFitAtts(int);
std::string
PyModelFitAtts_ToString(const ModelFitAtts *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    {   const stringVector &Vars = atts->GetVars();
        snprintf(tmpStr, 1000, "%sVars = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < Vars.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", Vars[i].c_str());
            str += tmpStr;
            if(i < Vars.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const intVector &numVars = atts->GetNumVars();
        snprintf(tmpStr, 1000, "%snumVars = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < numVars.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", numVars[i]);
            str += tmpStr;
            if(i < numVars.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const doubleVector &Tuples = atts->GetTuples();
        snprintf(tmpStr, 1000, "%sTuples = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < Tuples.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%g", Tuples[i]);
            str += tmpStr;
            if(i < Tuples.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const unsignedCharVector &StatTuples = atts->GetStatTuples();
        snprintf(tmpStr, 1000, "%sStatTuples = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < StatTuples.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", int(StatTuples[i]));
            str += tmpStr;
            if(i < StatTuples.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const intVector &numTups = atts->GetNumTups();
        snprintf(tmpStr, 1000, "%snumTups = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < numTups.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", numTups[i]);
            str += tmpStr;
            if(i < numTups.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const doubleVector &thold = atts->GetThold();
        snprintf(tmpStr, 1000, "%sthold = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < thold.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%g", thold[i]);
            str += tmpStr;
            if(i < thold.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const intVector &selectionType = atts->GetSelectionType();
        snprintf(tmpStr, 1000, "%sselectionType = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < selectionType.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", selectionType[i]);
            str += tmpStr;
            if(i < selectionType.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const intVector &distanceType = atts->GetDistanceType();
        snprintf(tmpStr, 1000, "%sdistanceType = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < distanceType.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", distanceType[i]);
            str += tmpStr;
            if(i < distanceType.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const intVector &inputSpace = atts->GetInputSpace();
        snprintf(tmpStr, 1000, "%sinputSpace = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < inputSpace.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", inputSpace[i]);
            str += tmpStr;
            if(i < inputSpace.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const stringVector &modelNames = atts->GetModelNames();
        snprintf(tmpStr, 1000, "%smodelNames = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < modelNames.size(); ++i)
        {
            snprintf(tmpStr, 1000, "\"%s\"", modelNames[i].c_str());
            str += tmpStr;
            if(i < modelNames.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    {   const intVector &modelNums = atts->GetModelNums();
        snprintf(tmpStr, 1000, "%smodelNums = (", prefix);
        str += tmpStr;
        for(size_t i = 0; i < modelNums.size(); ++i)
        {
            snprintf(tmpStr, 1000, "%d", modelNums[i]);
            str += tmpStr;
            if(i < modelNums.size() - 1)
            {
                snprintf(tmpStr, 1000, ", ");
                str += tmpStr;
            }
        }
        snprintf(tmpStr, 1000, ")\n");
        str += tmpStr;
    }
    return str;
}

static PyObject *
ModelFitAtts_Notify(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ModelFitAtts_SetVars(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->GetVars() = vec;
    // Mark the Vars in the object as modified.
    obj->data->SelectVars();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ModelFitAtts_GetVars(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;
    // Allocate a tuple the with enough entries to hold the Vars.
    const stringVector &Vars = obj->data->GetVars();
    PyObject *retval = PyTuple_New(Vars.size());
    for(size_t i = 0; i < Vars.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(Vars[i].c_str()));
    return retval;
}

/*static*/ PyObject *
ModelFitAtts_SetNumVars(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetNumVars() = vec;
    // Mark the numVars in the object as modified.
    obj->data->SelectNumVars();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ModelFitAtts_GetNumVars(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;
    // Allocate a tuple the with enough entries to hold the numVars.
    const intVector &numVars = obj->data->GetNumVars();
    PyObject *retval = PyTuple_New(numVars.size());
    for(size_t i = 0; i < numVars.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(numVars[i])));
    return retval;
}

/*static*/ PyObject *
ModelFitAtts_SetTuples(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;

    doubleVector vec;

    if (PyNumber_Check(args))
    {
        double val = PyFloat_AsDouble(args);
        double cval = double(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ double");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ double");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            double val = PyFloat_AsDouble(item);
            double cval = double(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more doubles");

    obj->data->GetTuples() = vec;
    // Mark the Tuples in the object as modified.
    obj->data->SelectTuples();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ModelFitAtts_GetTuples(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;
    // Allocate a tuple the with enough entries to hold the Tuples.
    const doubleVector &Tuples = obj->data->GetTuples();
    PyObject *retval = PyTuple_New(Tuples.size());
    for(size_t i = 0; i < Tuples.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(Tuples[i]));
    return retval;
}

/*static*/ PyObject *
ModelFitAtts_SetStatTuples(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;

    typedef unsigned char uchar;
    ucharVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        uchar cval = uchar(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ uchar");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ uchar");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            uchar cval = uchar(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ uchar", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ uchar", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more uchars");

    obj->data->GetStatTuples() = vec;
    // Mark the StatTuples in the object as modified.
    obj->data->SelectStatTuples();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ModelFitAtts_GetStatTuples(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;
    // Allocate a tuple the with enough entries to hold the StatTuples.
    const unsignedCharVector &StatTuples = obj->data->GetStatTuples();
    PyObject *retval = PyTuple_New(StatTuples.size());
    for(size_t i = 0; i < StatTuples.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(StatTuples[i])));
    return retval;
}

/*static*/ PyObject *
ModelFitAtts_SetNumTups(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetNumTups() = vec;
    // Mark the numTups in the object as modified.
    obj->data->SelectNumTups();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ModelFitAtts_GetNumTups(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;
    // Allocate a tuple the with enough entries to hold the numTups.
    const intVector &numTups = obj->data->GetNumTups();
    PyObject *retval = PyTuple_New(numTups.size());
    for(size_t i = 0; i < numTups.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(numTups[i])));
    return retval;
}

/*static*/ PyObject *
ModelFitAtts_SetThold(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;

    doubleVector vec;

    if (PyNumber_Check(args))
    {
        double val = PyFloat_AsDouble(args);
        double cval = double(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ double");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ double");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            double val = PyFloat_AsDouble(item);
            double cval = double(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ double", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ double", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more doubles");

    obj->data->GetThold() = vec;
    // Mark the thold in the object as modified.
    obj->data->SelectThold();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ModelFitAtts_GetThold(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;
    // Allocate a tuple the with enough entries to hold the thold.
    const doubleVector &thold = obj->data->GetThold();
    PyObject *retval = PyTuple_New(thold.size());
    for(size_t i = 0; i < thold.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyFloat_FromDouble(thold[i]));
    return retval;
}

/*static*/ PyObject *
ModelFitAtts_SetSelectionType(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetSelectionType() = vec;
    // Mark the selectionType in the object as modified.
    obj->data->SelectSelectionType();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ModelFitAtts_GetSelectionType(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;
    // Allocate a tuple the with enough entries to hold the selectionType.
    const intVector &selectionType = obj->data->GetSelectionType();
    PyObject *retval = PyTuple_New(selectionType.size());
    for(size_t i = 0; i < selectionType.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(selectionType[i])));
    return retval;
}

/*static*/ PyObject *
ModelFitAtts_SetDistanceType(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetDistanceType() = vec;
    // Mark the distanceType in the object as modified.
    obj->data->SelectDistanceType();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ModelFitAtts_GetDistanceType(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;
    // Allocate a tuple the with enough entries to hold the distanceType.
    const intVector &distanceType = obj->data->GetDistanceType();
    PyObject *retval = PyTuple_New(distanceType.size());
    for(size_t i = 0; i < distanceType.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(distanceType[i])));
    return retval;
}

/*static*/ PyObject *
ModelFitAtts_SetInputSpace(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetInputSpace() = vec;
    // Mark the inputSpace in the object as modified.
    obj->data->SelectInputSpace();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ModelFitAtts_GetInputSpace(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;
    // Allocate a tuple the with enough entries to hold the inputSpace.
    const intVector &inputSpace = obj->data->GetInputSpace();
    PyObject *retval = PyTuple_New(inputSpace.size());
    for(size_t i = 0; i < inputSpace.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(inputSpace[i])));
    return retval;
}

/*static*/ PyObject *
ModelFitAtts_SetModelNames(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;

    stringVector vec;

    if (PyUnicode_Check(args))
    {
        char const *val = PyUnicode_AsUTF8(args);
        std::string cval = std::string(val);
        if (val == 0 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ string");
        }
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyUnicode_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a unicode string", (int) i);
            }

            char const *val = PyUnicode_AsUTF8(item);
            std::string cval = std::string(val);

            if (val == 0 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ string", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more string(s)");

    obj->data->GetModelNames() = vec;
    // Mark the modelNames in the object as modified.
    obj->data->SelectModelNames();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ModelFitAtts_GetModelNames(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;
    // Allocate a tuple the with enough entries to hold the modelNames.
    const stringVector &modelNames = obj->data->GetModelNames();
    PyObject *retval = PyTuple_New(modelNames.size());
    for(size_t i = 0; i < modelNames.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyString_FromString(modelNames[i].c_str()));
    return retval;
}

/*static*/ PyObject *
ModelFitAtts_SetModelNums(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;

    intVector vec;

    if (PyNumber_Check(args))
    {
        long val = PyLong_AsLong(args);
        int cval = int(val);
        if (val == -1 && PyErr_Occurred())
        {
            PyErr_Clear();
            return PyErr_Format(PyExc_TypeError, "number not interpretable as C++ int");
        }
        if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            return PyErr_Format(PyExc_ValueError, "number not interpretable as C++ int");
        vec.resize(1);
        vec[0] = cval;
    }
    else if (PySequence_Check(args) && !PyUnicode_Check(args))
    {
        vec.resize(PySequence_Size(args));
        for (Py_ssize_t i = 0; i < PySequence_Size(args); i++)
        {
            PyObject *item = PySequence_GetItem(args, i);

            if (!PyNumber_Check(item))
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_TypeError, "arg %d is not a number type", (int) i);
            }

            long val = PyLong_AsLong(item);
            int cval = int(val);

            if (val == -1 && PyErr_Occurred())
            {
                Py_DECREF(item);
                PyErr_Clear();
                return PyErr_Format(PyExc_TypeError, "arg %d not interpretable as C++ int", (int) i);
            }
            if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
            {
                Py_DECREF(item);
                return PyErr_Format(PyExc_ValueError, "arg %d not interpretable as C++ int", (int) i);
            }
            Py_DECREF(item);

            vec[i] = cval;
        }
    }
    else
        return PyErr_Format(PyExc_TypeError, "arg(s) must be one or more ints");

    obj->data->GetModelNums() = vec;
    // Mark the modelNums in the object as modified.
    obj->data->SelectModelNums();

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
ModelFitAtts_GetModelNums(PyObject *self, PyObject *args)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)self;
    // Allocate a tuple the with enough entries to hold the modelNums.
    const intVector &modelNums = obj->data->GetModelNums();
    PyObject *retval = PyTuple_New(modelNums.size());
    for(size_t i = 0; i < modelNums.size(); ++i)
        PyTuple_SET_ITEM(retval, i, PyInt_FromLong(long(modelNums[i])));
    return retval;
}



PyMethodDef PyModelFitAtts_methods[MODELFITATTS_NMETH] = {
    {"Notify", ModelFitAtts_Notify, METH_VARARGS},
    {"SetVars", ModelFitAtts_SetVars, METH_VARARGS},
    {"GetVars", ModelFitAtts_GetVars, METH_VARARGS},
    {"SetNumVars", ModelFitAtts_SetNumVars, METH_VARARGS},
    {"GetNumVars", ModelFitAtts_GetNumVars, METH_VARARGS},
    {"SetTuples", ModelFitAtts_SetTuples, METH_VARARGS},
    {"GetTuples", ModelFitAtts_GetTuples, METH_VARARGS},
    {"SetStatTuples", ModelFitAtts_SetStatTuples, METH_VARARGS},
    {"GetStatTuples", ModelFitAtts_GetStatTuples, METH_VARARGS},
    {"SetNumTups", ModelFitAtts_SetNumTups, METH_VARARGS},
    {"GetNumTups", ModelFitAtts_GetNumTups, METH_VARARGS},
    {"SetThold", ModelFitAtts_SetThold, METH_VARARGS},
    {"GetThold", ModelFitAtts_GetThold, METH_VARARGS},
    {"SetSelectionType", ModelFitAtts_SetSelectionType, METH_VARARGS},
    {"GetSelectionType", ModelFitAtts_GetSelectionType, METH_VARARGS},
    {"SetDistanceType", ModelFitAtts_SetDistanceType, METH_VARARGS},
    {"GetDistanceType", ModelFitAtts_GetDistanceType, METH_VARARGS},
    {"SetInputSpace", ModelFitAtts_SetInputSpace, METH_VARARGS},
    {"GetInputSpace", ModelFitAtts_GetInputSpace, METH_VARARGS},
    {"SetModelNames", ModelFitAtts_SetModelNames, METH_VARARGS},
    {"GetModelNames", ModelFitAtts_GetModelNames, METH_VARARGS},
    {"SetModelNums", ModelFitAtts_SetModelNums, METH_VARARGS},
    {"GetModelNums", ModelFitAtts_GetModelNums, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
ModelFitAtts_dealloc(PyObject *v)
{
   ModelFitAttsObject *obj = (ModelFitAttsObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *ModelFitAtts_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyModelFitAtts_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "Vars") == 0)
        return ModelFitAtts_GetVars(self, NULL);
    if(strcmp(name, "numVars") == 0)
        return ModelFitAtts_GetNumVars(self, NULL);
    if(strcmp(name, "Tuples") == 0)
        return ModelFitAtts_GetTuples(self, NULL);
    if(strcmp(name, "StatTuples") == 0)
        return ModelFitAtts_GetStatTuples(self, NULL);
    if(strcmp(name, "numTups") == 0)
        return ModelFitAtts_GetNumTups(self, NULL);
    if(strcmp(name, "thold") == 0)
        return ModelFitAtts_GetThold(self, NULL);
    if(strcmp(name, "selectionType") == 0)
        return ModelFitAtts_GetSelectionType(self, NULL);
    if(strcmp(name, "distanceType") == 0)
        return ModelFitAtts_GetDistanceType(self, NULL);
    if(strcmp(name, "inputSpace") == 0)
        return ModelFitAtts_GetInputSpace(self, NULL);
    if(strcmp(name, "modelNames") == 0)
        return ModelFitAtts_GetModelNames(self, NULL);
    if(strcmp(name, "modelNums") == 0)
        return ModelFitAtts_GetModelNums(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyModelFitAtts_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyModelFitAtts_methods[i].ml_name),
                PyString_FromString(PyModelFitAtts_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyModelFitAtts_methods, self, name);
}

int
PyModelFitAtts_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "Vars") == 0)
        obj = ModelFitAtts_SetVars(self, args);
    else if(strcmp(name, "numVars") == 0)
        obj = ModelFitAtts_SetNumVars(self, args);
    else if(strcmp(name, "Tuples") == 0)
        obj = ModelFitAtts_SetTuples(self, args);
    else if(strcmp(name, "StatTuples") == 0)
        obj = ModelFitAtts_SetStatTuples(self, args);
    else if(strcmp(name, "numTups") == 0)
        obj = ModelFitAtts_SetNumTups(self, args);
    else if(strcmp(name, "thold") == 0)
        obj = ModelFitAtts_SetThold(self, args);
    else if(strcmp(name, "selectionType") == 0)
        obj = ModelFitAtts_SetSelectionType(self, args);
    else if(strcmp(name, "distanceType") == 0)
        obj = ModelFitAtts_SetDistanceType(self, args);
    else if(strcmp(name, "inputSpace") == 0)
        obj = ModelFitAtts_SetInputSpace(self, args);
    else if(strcmp(name, "modelNames") == 0)
        obj = ModelFitAtts_SetModelNames(self, args);
    else if(strcmp(name, "modelNums") == 0)
        obj = ModelFitAtts_SetModelNums(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
ModelFitAtts_print(PyObject *v, FILE *fp, int flags)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)v;
    fprintf(fp, "%s", PyModelFitAtts_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
ModelFitAtts_str(PyObject *v)
{
    ModelFitAttsObject *obj = (ModelFitAttsObject *)v;
    return PyString_FromString(PyModelFitAtts_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *ModelFitAtts_Purpose = "This file contains attributes for the ModelFit operator.";
#else
static char *ModelFitAtts_Purpose = "This file contains attributes for the ModelFit operator.";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(ModelFitAttsType,         \
                  "ModelFitAtts",           \
                  ModelFitAttsObject,       \
                  ModelFitAtts_dealloc,     \
                  ModelFitAtts_print,       \
                  PyModelFitAtts_getattr,   \
                  PyModelFitAtts_setattr,   \
                  ModelFitAtts_str,         \
                  ModelFitAtts_Purpose,     \
                  ModelFitAtts_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
ModelFitAtts_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &ModelFitAttsType
         || Py_TYPE(other) != &ModelFitAttsType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    ModelFitAtts *a = ((ModelFitAttsObject *)self)->data;
    ModelFitAtts *b = ((ModelFitAttsObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static ModelFitAtts *defaultAtts = 0;
static ModelFitAtts *currentAtts = 0;

static PyObject *
NewModelFitAtts(int useCurrent)
{
    ModelFitAttsObject *newObject;
    newObject = PyObject_NEW(ModelFitAttsObject, &ModelFitAttsType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new ModelFitAtts(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new ModelFitAtts(*defaultAtts);
    else
        newObject->data = new ModelFitAtts;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapModelFitAtts(const ModelFitAtts *attr)
{
    ModelFitAttsObject *newObject;
    newObject = PyObject_NEW(ModelFitAttsObject, &ModelFitAttsType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (ModelFitAtts *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
ModelFitAtts_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewModelFitAtts(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef ModelFitAttsMethods[] = {
    {"ModelFitAtts", ModelFitAtts_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *ModelFitAttsObserver = 0;

std::string
PyModelFitAtts_GetLogString()
{
    std::string s("ModelFitAtts = ModelFitAtts()\n");
    if(currentAtts != 0)
        s += PyModelFitAtts_ToString(currentAtts, "ModelFitAtts.", true);
    return s;
}

static void
PyModelFitAtts_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("ModelFitAtts = ModelFitAtts()\n");
        s += PyModelFitAtts_ToString(currentAtts, "ModelFitAtts.", true);
        cb(s);
    }
}

void
PyModelFitAtts_StartUp(ModelFitAtts *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyModelFitAtts_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(ModelFitAttsObserver == 0)
    {
        ModelFitAttsObserver = new ObserverToCallback(subj,
            PyModelFitAtts_CallLogRoutine, (void *)data);
    }

}

void
PyModelFitAtts_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete ModelFitAttsObserver;
    ModelFitAttsObserver = 0;
}

PyMethodDef *
PyModelFitAtts_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return ModelFitAttsMethods;
}

bool
PyModelFitAtts_Check(PyObject *obj)
{
    return (obj->ob_type == &ModelFitAttsType);
}

ModelFitAtts *
PyModelFitAtts_FromPyObject(PyObject *obj)
{
    ModelFitAttsObject *obj2 = (ModelFitAttsObject *)obj;
    return obj2->data;
}

PyObject *
PyModelFitAtts_New()
{
    return NewModelFitAtts(0);
}

PyObject *
PyModelFitAtts_Wrap(const ModelFitAtts *attr)
{
    return WrapModelFitAtts(attr);
}

void
PyModelFitAtts_SetParent(PyObject *obj, PyObject *parent)
{
    ModelFitAttsObject *obj2 = (ModelFitAttsObject *)obj;
    obj2->parent = parent;
}

void
PyModelFitAtts_SetDefaults(const ModelFitAtts *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new ModelFitAtts(*atts);
}

